package cn.itsource.ymcc.controller;

import cn.itsource.ymcc.doc.CourseDoc;
import cn.itsource.ymcc.dto.CourseSearchDTO;
import cn.itsource.ymcc.result.JSONResult;
import cn.itsource.ymcc.result.PageList;
import cn.itsource.ymcc.service.ICourseSearchService;
import cn.itsource.ymcc.vo.AggPageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CourseSearchController {
    @Autowired
    private ICourseSearchService iCourseSearchService;
    @PostMapping("/course/save")
    public JSONResult save(@RequestBody CourseDoc doc){
        iCourseSearchService.save(doc);
        return JSONResult.success();
    }

    @PostMapping("/course/delete/{id}")
    public JSONResult delete(@PathVariable("id") Long id){
        iCourseSearchService.delete(id);
        return JSONResult.success();
    }

    @PostMapping("/course/search")
    public JSONResult search(@RequestBody CourseSearchDTO dto){
        AggPageList<CourseDoc> list = iCourseSearchService.search(dto);
        return JSONResult.success(list);
    }
}
